package com.kylin.module.user.business;

import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

import com.kylin.common.exception.BusinessException;

import com.kylin.common.paginate.DisplayPage;
import com.kylin.common.paginate.PageManager;

import com.kylin.hibernate.BaseHibernateDAO;
import com.kylin.hibernate.CriteriaInfo;
import com.kylin.module.admin.business.ManageCatDictBlogic;
import com.kylin.module.community.forms.MemberForm;
import com.kylin.module.community.orm.Member;
import com.kylin.module.user.orm.User;
import com.kylin.module.user.orm.UserDAO;

import org.apache.log4j.Logger;


public class UserBlogic {
	
	private int psgeSize = 15;
	protected static Logger log = Logger.getLogger(ManageCatDictBlogic.class);

	public DisplayPage getUserList(int pageNum, CriteriaInfo cinfo) throws BusinessException {
		log.info("search cat page " + pageNum);
		DisplayPage page = PageManager.getDisplayPage(psgeSize, pageNum, cinfo);
		return page;
	}
	
	
	public User loginUser(String username, String password){
		
		UserDAO udao = new UserDAO();		
		User user =  udao.login(username, password);		
		return user;
		
	}
	
	/**
	 * 
	 * @param userId
	 * @param oldPass
	 * @param newPass
	 * @throws BusinessException
	 */
	public void changePassword(String userId,String oldPass,String newPass) throws BusinessException {
		User user = (User) BaseHibernateDAO.findById(User.class, new Long(userId) );
		if(user == null)
			throw new BusinessException("未找到用户信息");
		if(! oldPass.equals(user.getPassword()))
			throw new BusinessException("输入的原密码不正确");
		user.setPassword(newPass);
		BaseHibernateDAO.save(user) ;
	}
	
	/*
	public Long findUser(String username, String password){
	  
	}
	*/
	
}
